home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / byt86feb.arc / VISUAL.LBR / XLISPVSD < prev   
Text File  |  1986-04-11  |  6KB  |  535 lines

  1.  
  2. ; BYSO Visual Syntax Editor-Limited Version
  3.  
  4. ; Copyright (C) 1985 Raphael L. Levien
  5.  
  6. ; ALL RIGHTS RESERVED
  7.  
  8.  
  9.  
  10. ; Converted for XLISP version 1.5c on the IBM-PC by David Betz
  11.  
  12.  
  13.  
  14. (putprop 'defun 'defund 'vsd)
  15.  
  16. (putprop 'quote 'quoted 'vsd)
  17.  
  18.  
  19.  
  20. (setq *he* nil)
  21.  
  22.  
  23.  
  24. (defun vsd (l)
  25.  
  26.  (let ((old-he *he*))
  27.  
  28.   (clear)
  29.  
  30.   (setq *he* (gensym))
  31.  
  32.   (vsd1 l 160)
  33.  
  34.   (setq *he* old-he)
  35.  
  36.   (setc 3360)))
  37.  
  38.  
  39.  
  40. (defun vsd1 (l p)
  41.  
  42.  (if (eq *he* l)
  43.  
  44.   (highlt l p)
  45.  
  46.   (if (consp l)
  47.  
  48.    (if (and (symbolp (car l)) (get (car l) 'vsd))
  49.  
  50.     (funcall (get (car l) 'vsd) l p)
  51.  
  52.     (adj
  53.  
  54.      (car l)
  55.  
  56.      p
  57.  
  58.      (vsd4 (cdr l) (vsd3 (car l) p))))
  59.  
  60.    (vsd2 l p))))
  61.  
  62.  
  63.  
  64. (defun vsd2 (l p)
  65.  
  66.  (prog1
  67.  
  68.   (setc (- p (* (flatc l) 2)))
  69.  
  70.   (princ l)))
  71.  
  72.  
  73. (defun vsd3 (a p)
  74.  
  75.  (let* ((sl (flatc a))
  76.  
  77.     (b (- p (+ sl sl 4))))
  78.  
  79.   (setc b)
  80.  
  81.   (write-char 218)
  82.  
  83.   (dotimes (i sl) (write-char 196))
  84.  
  85.   (write-char 191)
  86.  
  87.   (setc (+ 160 b))
  88.  
  89.   (write-char 179)
  90.  
  91.   (princ a)
  92.  
  93.   (write-char 195)
  94.  
  95.   (setc (+ b 320))
  96.  
  97.   (write-char 192)
  98.  
  99.   (dotimes (i sl) (write-char 196))
  100.  
  101.   (write-char 217)
  102.  
  103.   b))
  104.  
  105.  
  106.  
  107. (defun adj (a p h)
  108.  
  109.  (let* ((sl (flatc a))
  110.  
  111.     (b (- p (+ sl sl -316)))
  112.  
  113.     (top (- (max b (car h)) 160)))
  114.  
  115.   (setc (do ((i b (+ i 160)))
  116.  
  117.          ((> i top) i)
  118.  
  119.      (setc i)
  120.  
  121.      (write-char 179)
  122.  
  123.      (dotimes (i sl) (write-char 32))
  124.  
  125.      (write-char 179)))
  126.  
  127.   (write-char 192)
  128.  
  129.   (dotimes (i sl) (write-char 196))
  130.  
  131.   (write-char 217)
  132.  
  133.   (max b (- (cdr h) 160))))
  134.  
  135.  
  136.  
  137. (defun vsd4 (a p)
  138.  
  139.  (do ((l a (cdr l))
  140.  
  141.       (c p))
  142.  
  143.   ((null l)
  144.  
  145.    (cons (+ c 160)
  146.  
  147.     p))
  148.  
  149.   (setc (setq c (+ p (if (consp (car l))
  150.  
  151.               156
  152.  
  153.               -4))))
  154.  
  155.   (write-char 196)
  156.  
  157.   (write-char 26)
  158.  
  159.   (setq p (+ (* 160 (/ (vsd1 (car l)
  160.  
  161.             (- p 4))
  162.  
  163.              160))
  164.  
  165.        (rem p 160)
  166.  
  167.        160))))
  168.  
  169.  
  170.  
  171. (defun defund (l p)
  172.  
  173.  (setc 0)
  174.  
  175.  (msg "Function: " (cadr l)
  176.  
  177.   t
  178.  
  179.   "Variables:")
  180.  
  181.  (if (and (nth 2 l)
  182.  
  183.       (atom (nth 2 l)))
  184.  
  185.   (setq l (cdr l)))
  186.  
  187.  (do ((tl (nth 2 l)
  188.  
  189.        (cdr tl)))
  190.  
  191.   ((null tl))
  192.  
  193.   (msg " " (car tl)))
  194.  
  195.  (vsd1 (if (nthcdr 4 l)
  196.  
  197.     (cons 'progn (nthcdr 3 l))
  198.  
  199.     (nth 3 l))
  200.  
  201.   p))
  202.  
  203.  
  204.  
  205. (defun quoted (l p)
  206.  
  207.  (vsd2 (cadr l)
  208.  
  209.   (+ 160 p)))
  210.  
  211.  
  212.  
  213. (defun highlt (l p)
  214.  
  215.  (let ((old-he *he*))
  216.  
  217.   (let (r)
  218.  
  219.    (set-inverse t)
  220.  
  221.    (setq *he* (gensym))
  222.  
  223.    (setq r (vsd1 l p))
  224.  
  225.    (setq *he* old-he)
  226.  
  227.    (set-inverse nil)
  228.  
  229.    r)))
  230.  
  231.  
  232.  
  233. (defun in (x y)
  234.  
  235.  (if (null y)
  236.  
  237.   x
  238.  
  239.   (nth (car y)
  240.  
  241.    (in x (cdr y)))))
  242.  
  243.  
  244.  
  245. (defun ins (z y v)
  246.  
  247.  (if (null y)
  248.  
  249.   (setq *x* v)
  250.  
  251.   (setf (nth (car y)
  252.  
  253.      (in z (cdr y)))
  254.  
  255.    v)))
  256.  
  257.  
  258.  
  259. (defun edv (x)
  260.  
  261.  (prog (com)
  262.  
  263.   (setq *x* (subst nil nil x)
  264.  
  265.     *curs*
  266.  
  267.       (if (and (consp *x*)
  268.  
  269.            (eq (car *x*)
  270.  
  271.                'defun))
  272.  
  273.           (list (if (and (nth 2 *x*)
  274.  
  275.                  (atom (nth 2 *x*)))
  276.  
  277.             4
  278.  
  279.             3))
  280.  
  281.           nil))
  282.  
  283.   (clear)
  284.  
  285.   a
  286.  
  287.   (dhlt *x*)
  288.  
  289.   (setq com (get-key))
  290.  
  291.   (if (= com 27)    ; escape
  292.  
  293.    (stoped))
  294.  
  295.   (if (= com 200)    ; up
  296.  
  297.    (if *curs* (setf (car *curs*) (1- (car *curs*)))))
  298.  
  299.   (if (= com 203)    ; left
  300.  
  301.    (setq *curs* (cons 1 *curs*)))
  302.  
  303.   (if (= com 205)    ; right
  304.  
  305.    (setq *curs* (cdr *curs*)))
  306.  
  307.   (if (= com 208)    ; down
  308.  
  309.    (if *curs* (setf (car *curs*) (1+ (car *curs*)))))
  310.  
  311.   (if (= com 99)    ; (c)hange
  312.  
  313.    (chel))
  314.  
  315.   (if (= com 97)    ; (a)dd
  316.  
  317.    (addarg))
  318.  
  319.   (if (= com 105)    ; (i)nsert
  320.  
  321.    (inel))
  322.  
  323.   (if (= com 100)    ; (d)elete
  324.  
  325.    (delel))
  326.  
  327.   (if (= com 116)    ; (t)est
  328.  
  329.    (testel))
  330.  
  331.   (go a)))
  332.  
  333.  
  334.  
  335. (defun dhlt (l)
  336.  
  337.   (let ((old-he *he*))
  338.  
  339.     (setq *he* (in l *curs*))
  340.  
  341.     (vsd1 l 160)
  342.  
  343.     (setq *he* old-he)
  344.  
  345.     (setc 3360)))
  346.  
  347.  
  348.  
  349. (defun chel ()
  350.  
  351.   (msg "Change to")
  352.  
  353.   (ins *x* *curs* (readel "Change to: "))
  354.  
  355.   (clear))
  356.  
  357.  
  358.  
  359. (defun readel (m)
  360.  
  361.   (msg " a)tom or f)unction? ")
  362.  
  363.   (if (= (get-key) 102)
  364.  
  365.     (progn
  366.  
  367.       (msg "function" t m)
  368.  
  369.       (list (read)))
  370.  
  371.     (progn
  372.  
  373.       (msg "atom" t m)
  374.  
  375.       (read))))
  376.  
  377.  
  378.  
  379. (defun addarg ()
  380.  
  381.   (msg "Add argument")
  382.  
  383.   (setf (cdr (last (in *x* *curs*)))
  384.  
  385.     (list (readel "Argument: ")))
  386.  
  387.   (clear))
  388.  
  389.  
  390.  
  391. (defun inel ()
  392.  
  393.   (when *curs*
  394.  
  395.     (msg "Insert")
  396.  
  397.     (setf (cdr (nthcdr (1- (car *curs*))
  398.  
  399.                (in *x* (cdr *curs*))))
  400.  
  401.       (cons (readel "Insert: ")
  402.  
  403.         (nthcdr (car *curs*)
  404.  
  405.             (in *x* (cdr *curs*)))))
  406.  
  407.     (clear)))
  408.  
  409.  
  410.  
  411. (defun delel ()
  412.  
  413.   (when *curs*
  414.  
  415.     (setf (cdr (nthcdr (1- (car *curs*))
  416.  
  417.                (in *x* (cdr *curs*))))
  418.  
  419.       (nthcdr (1+ (car *curs*))
  420.  
  421.           (in *x* (cdr *curs*))))
  422.  
  423.     (if (not (nthcdr (car *curs*)
  424.  
  425.              (in *x* (cdr *curs*))))
  426.  
  427.       (if (= (car *curs*) 1)
  428.  
  429.     
  430.     (setq *curs* (cdr *curs*))
  431.  
  432.     (setf (car *curs*) (1- (car *curs*)))))
  433.  
  434.     (clear)))
  435.  
  436.  
  437.  
  438. (defun testexp (exp)
  439.  
  440.   (prog (val)
  441.  
  442.     (setq val (eval exp))
  443.  
  444.     (msg "Value: ")
  445.  
  446.     (print val)
  447.  
  448.     (msg "Press any key to return to editor: ")
  449.  
  450.     (get-key)
  451.  
  452.     (clear)))
  453.  
  454.  
  455.  
  456. (defun testel ()
  457.  
  458.   (if *curs*
  459.  
  460.     (progn
  461.  
  462.       (msg "w)hole display or h)ighlighted area? ")
  463.  
  464.       (if (= (get-key) 104)
  465.  
  466.     (progn
  467.  
  468.       (msg "highlighted area" t)
  469.  
  470.       (testexp (in *x* *curs*)))
  471.  
  472.     (progn
  473.  
  474.       (msg "whole display" t)
  475.  
  476.       (testexp *x*))))
  477.  
  478.     (testexp *x*)))
  479.  
  480.  
  481.  
  482. (defun stoped ()
  483.  
  484.   (msg "Are you sure you want to exit the editor? ")
  485.  
  486.   (if (= (get-key) 121)
  487.  
  488.     (progn
  489.  
  490.       (terpri)
  491.  
  492.       (return *x*))
  493.  
  494.   (clear)))
  495.  
  496.  
  497.  
  498. (defun ask (m)
  499.  
  500.   (msg m)
  501.  
  502.   (read))
  503.  
  504.  
  505.  
  506. ; functions required for XLISP
  507.  
  508.  
  509.  
  510. (defun setc (p)
  511.  
  512.   (set-cursor (/ p 160) (rem (/ p 2) 80))
  513.  
  514.   p)
  515.  
  516.  
  517.  
  518. (defun msg (&rest args)
  519.  
  520.   (mapcar #'(lambda (x) (if (eq x t) (terpri) (princ x)))
  521.  
  522.       args))
  523.  
  524.  
  525.  
  526. (expand 1)
  527.  
  528.  
  529. 
  530.  
  531.  
  532. (defun msg (&rest args)
  533.  
  534.   (mapcar #'(lambda (x) (if (eq x t) (terpri) (princ x)))
  535.